<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>发布朋友圈</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="../assets/css/amazeui.min.css?v=2.9">
    <link rel="stylesheet" href="../assets/css/style.css?v=2.3">
    <link rel="stylesheet" href="../assets/css/index.css?v=2.3">
    <link rel="stylesheet" href="../assets/css/extend.css?v=2.3">
    <link rel="stylesheet" href="../assets/css/icons.css?v=2.3">
    <link rel="stylesheet" href="../assets/js/layui/css/layui.css">
    <script type='text/javascript' src='../assets/js/layui/layui.js'></script>
</head>
<body class="bg-gray">
<!--<header data-am-widget="header" class="am-header am-header-default am-header-fixed ">

    <div class="am-header-left am-header-nav">
        <a onclick="history.go(-1)" class="widht-10s">
            <i class="icon_8"></i>
        </a>
    </div>
    <h1 class="am-header-title">
        发布朋友圈
    </h1>


</header>-->
<section class="" id="amz-main" data-tag="css-nav">
    <div class="am-g  bg-white     font-14   ">
        <div class="am-u-sm-12  address-padding am-padding-left-sm">
            <textarea class="teshu-yaoqiu" rows="5" placeholder="说点什么呢"></textarea>
        </div>
        <div class="am-u-sm-12 post">
            <p class="friend-mar0" id="imgs">
                <!--<img class="list-img" src="../assets/images/uploads/0.jpg" style="height: 100px;">-->

            </p>
            <img class="list-img " src="../assets/images/icons/add-img.png" style="height: 100px;"
                 onclick="$('.fileupload').click()">
            <form id="uploadForm" enctype="multipart/form-data">

                <input style="display: none" class="fileupload" name="editormd-image-file"
                       type="file" onchange="uploadPic(this)">
            </form>
        </div>
    </div>
    <div class="am-padding-left-sm am-margin-top-sm am-padding-right-sm">
        <div class="btn-88" onclick="sendCircle()">发布</div>
    </div>
    <div class="am-padding-left-sm am-margin-top-sm am-padding-right-sm">
        <div class="btn-88 white-border">取消</div>
    </div>

</section>

<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/amazeui.min.js"></script>
<script src="../assets/js/vue2.2.2.min.js"></script>
<script src="../assets/common.js"></script>
<script>
    var mask;
    layui.use('layer', function(){
        var layer = layui.layer;
    });
    var sessionid = getQueryString("sessionid");
    var img_urls=[];
    var ids=0;
    //上传图片
    function uploadPic(that) {
        var formData = new FormData($('#uploadForm')[0]);
        mask = layer.msg('正在上传图片', {icon: 16});
        $.ajax({
            type: 'post',
            url: baseUrl + "v1.0/upload",
            data: formData,
            cache: false,
            processData: false,
            contentType: false,
            dataType: "json",
            field: 'editormd-image-file',
            success: function (d) {
                img_urls.push(d.url);
                var html='<img id="_'+ids+'" class="list-img" src="'+d.url+' " style="height: 100px;" onclick="del(\''+d.url+'\',\''+'_'+ids+'\')" )">'
                $("#imgs").append(html);
                ids++;
                layer.close(mask);
            }
        })
    }

    function del(url,id){
        img_urls.remove(url);
        $("#"+id).remove();
    }
    Array.prototype.remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
    function sendCircle(){
        var circledata={
            "content": $(".teshu-yaoqiu").val(),
            "img_urls": img_urls
        }
        mask = layer.msg('正在发送', {icon: 16});
        $.ajax({
            url:baseUrl+'v3.0/user/Circle',
            type: 'post',
            headers: {'session_id': sessionid},
            contentType: 'application/json',
            data: JSON.stringify(circledata),
            success:function(){
                layer.close(mask);
                window.location.href='我的朋友圈.html?sessionid='+sessionid
            }
        })
    }
    $(function () {
        setTimeout(function(){
            mask = layer.msg('正在加载', {icon: 16});
        },200)
        setTimeout(function(){
            layer.close(mask);
        },500)

    })
</script>

</body>
</html>